﻿#include "stdafx.h"
#include "Clock.h"

#include <boost/date_time.hpp>

_NAMESPACE_BEGIN

LARGE_INTEGER Clock::frequent=LARGE_INTEGER();
void Clock::Start()
{
	QueryPerformanceCounter( &startTime);
}

double Clock::GetElapse()
{
	LARGE_INTEGER now;
	QueryPerformanceCounter( &now);
	__int64 elapse64 = (__int64)now.QuadPart-(__int64)startTime.QuadPart;
	return (double)elapse64/(double)frequent.QuadPart;
}

double Clock::GetCurTime()
{
	LARGE_INTEGER now;
	QueryPerformanceCounter( &now);
	__int64 nowtime = (__int64)now.QuadPart;
	return (double)nowtime/(double)frequent.QuadPart;
}

Clock::Clock()
{
	if(0==frequent.QuadPart)
		QueryPerformanceFrequency(&frequent);
	Start();
}


void Clock::GetSysTime(string& time)
{
	using namespace boost::posix_time;    
	using namespace boost::gregorian;

	ptime now = second_clock::local_time();
	time = to_simple_string(now);
}

_NAMESPACE_END